/**
  ******************************************************************************
  * @file
  * @brief
  * @author taoye
  * @version V1.0.0
  * @date 2022/08/01
  ******************************************************************************
  */

#ifndef ROM_MANAGE_H_
#define ROM_MANAGE_H_

/* Includes ------------------------------------------------------------------*/
#include "Amemory_default.h"
#include "public_crc32.h"
#include "public_list.h"
#include "stdbool.h"
#include "stdarg.h"


#define   AMEMORY_VERSION    "V0.0.3"


/* Public enum    -----------------------------------------------------------*/
typedef enum
{
    AMEM_String,
    AMEM_Crc32,
}Amem_nametype_e;

/* Public defines -----------------------------------------------------------*/
#define     Amem_Crc32_Write(area_name, data, offset_addr, size)                \
    ret_val = Amem_Area_Write(AMEM_Crc32, area_name, data, offset_addr, size);  \
    if(ret_val < 0)                                                             \

#define     Amem_Crc32_Read(area_name, data, offset_addr, size)                 \
    ret_val = Amem_Area_Read(AMEM_Crc32, area_name, data, offset_addr, size);   \
    if(ret_val < 0)                                                             \

#define     Amem_Crc32_FullErase(area_name)                                     \
    ret_val = Amem_Area_FullErase(AMEM_Crc32, area_name);                       \
    if(ret_val < 0)                                                             \

typedef int ( *Amem_Write )  ( uint32_t, uint8_t *,  size_t );
typedef int ( *Amem_Read  )  ( uint32_t, uint8_t *,  size_t );
typedef int ( *Amem_Erase )  ( uint32_t, size_t );

/* Public Struct  -----------------------------------------------------------*/
typedef struct {
    char            *st;    //名称
	uint32_t        name;   //crc32
    uint32_t        base_addr;
    uint8_t         align;
    size_t          size;
    size_t          used;
    Amem_Write      Write;
    Amem_Read       Read;
    Amem_Erase      Erase;

	slist_t         list;
} A_mem_hard_item_t;

typedef struct {
    char            *st;    //名称
	uint32_t        name;   //crc32
    uint32_t        hard_name;
    uint32_t        offset_addr;
    size_t          size;

    slist_t         list;
} A_mem_area_item_t;

/* Public Variable  ---------------------------------------------------------*/
//Pointer

//Array

//Const


/* Pubilc function prototypes -----------------------------------------------*/
A_mem_area_item_t * Find_Area
(
    uint32_t area_name );

A_mem_hard_item_t * Find_Hard
(
    uint32_t hard_name );

int Amem_Hardware_Register
(
    const char *    hard_name,
    uint32_t        base_addr,
    size_t          size,
    uint8_t         align,
    Amem_Write      Write, 
    Amem_Read       Read,  
    Amem_Erase      Erase );

int Amem_Area_Register
(
    const char *    area_name,
    const char *    hard_name,
    uint32_t        offset_addr,
    size_t          size );

int Amem_Check_Hardware
(
    Amem_nametype_e nametype,
    void        *   hard_name );

int Amem_Check_Area
(
    Amem_nametype_e nametype,
    void        *   area_name );

uint8_t Amem_Get_AreaAlign
(
    Amem_nametype_e nametype,
    void        *   area_name );

size_t Amem_Get_AreaSize
(
    Amem_nametype_e nametype,
    void        *   area_name );

Amem_Erase Amem_Get_AreaErase
(
    Amem_nametype_e nametype,
    void        *   area_name );

int Amem_Area_Write
(
    Amem_nametype_e nametype,
    void        *   area_name,
    uint8_t     *   data,
    uint32_t        offset_addr,
    size_t          size );

int Amem_Area_Read
(
    Amem_nametype_e nametype,
    void        *   area_name,
    uint8_t     *   data,
    uint32_t        offset_addr,
    size_t          size );

int Amem_Area_FullErase
(
    Amem_nametype_e nametype,
    void        *   area_name );

int Amem_Area_Erase
(
    Amem_nametype_e nametype,
    void        *   area_name,
    uint32_t        offset_addr,
    size_t          size );

slist_t *Get_Hard_list(void);
slist_t *Get_Area_list(void);

#endif


